package org.example.day;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/09/14 10:57
 */
public class Solution2390 {

    public static void main(String[] args) {

        List<String> testList = new ArrayList<>();
        testList.add("test1");
        testList.add("test2");
        testList.add("test3");
        List<String> testList2 = new ArrayList<>(testList);

        List<String> newList = new ArrayList<>(testList.size());
        Collections.copy(newList, testList);

        testList.remove("test1");
        testList.remove("test3");
        testList.remove("test4");
        System.out.println(testList.size());
        System.out.println(testList2.size());
        System.out.println(newList.size());
        System.out.println(testList.get(0));

        System.out.println(new Solution2390().removeStars2("leet**cod*e"));
    }


    public String removeStars2(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (char c : s.toCharArray()) {
            if(c == '*'){
                stringBuilder.deleteCharAt(stringBuilder.length()-1);
            }else {
                stringBuilder.append(c);
            }
        }
        return stringBuilder.toString();
    }

    public String removeStars(String s) {

        Stack<Character> stack = new Stack<>();

        for (char c : s.toCharArray()) {
            if(c == '*'){
                stack.pop();
            }else {
                stack.push(c);
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < stack.size(); i++) {
            stringBuilder.append(stack.get(i));
        }
        return stringBuilder.toString();
    }


}
